<?php
/**
 *
 * 功能说明：驾校列表控制器。
 *
 **/

namespace Home\Controller;

class SchoolListController extends ComController
{

    public function index()
    {
        $status = $_GET['status'];
        $this->assign('status', $status);
        $this->display();
    }
    public function index_ajax()
    {
        $status = $_POST['status'];
        $sort = $_POST['sort'] ? $_POST['sort'] : 'desc';
        $city = $_POST['city']? $_POST['city'] : '410100';
        $member = M('member');
        $prefix = C('DB_PREFIX');
        $keyword = isset($_POST['keyword']) ? htmlentities($_POST['keyword']) : '';
        $where = "1 = 1 and  {$prefix}member.uid !=1 and {$prefix}member.city = {$city} ";
        if ($keyword) {
            $where .= "and {$prefix}member.name like '%{$keyword}%' ";
        }
        //echo M('member')->where(array('city'=>'410100'))->count();die;
        $list=$member->where($where)
        ->field("min(c.price) as price,{$prefix}member.name,{$prefix}member.uid,{$prefix}member.content,{$prefix}member.head,{$prefix}member.address")
        ->join("{$prefix}class_level as c on c.d_id = {$prefix}member.uid",'LEFT')
        ->group("c.d_id")
        ->order("c.price {$sort}")
        ->select();
    
        if(empty($list)){
           echo 1;die;
        }
       
        $this->assign('status', $status);
        $this->assign('sort', $sort);
        $this->assign('list', $list);
        $this->display();

    }
    public function getCity(){
        $city = M('city')->where(array('pid'=>410000))->select();
        $this->assign('city',$city);
        $this->assign('status',$_POST['status']);
        $this->display();
    }

}
